/////////////////////////////////////////////////////////////////////////////
// Original code from libhdfs3. Copyright (c) 2013 - 2014, Pivotal Inc.
// All rights reserved. Author: Zhanwei Wang
/////////////////////////////////////////////////////////////////////////////
//  Modifications by Kumo Inc.
// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//



#pragma once

#include <kmhdfs/common/hash.h>

#include <cstdint>
#include <string>
#include <sstream>

namespace Hdfs {
namespace Internal {

class RpcServerInfo {
public:

    RpcServerInfo(const std::string & tokenService, const std::string & h, const std::string & p) :
        host(h), port(p), tokenService(tokenService) {
    }

    RpcServerInfo(const std::string & h, uint32_t p) :
        host(h) {
        std::stringstream ss;
        ss.imbue(std::locale::classic());
        ss << p;
        port = ss.str();
    }

    size_t hash_value() const;

    bool operator ==(const RpcServerInfo & other) const {
        return this->host == other.host && this->port == other.port && tokenService == other.tokenService;
    }

    const std::string & getTokenService() const {
        return tokenService;
    }

    const std::string & getHost() const {
        return host;
    }

    const std::string & getPort() const {
        return port;
    }

    void setTokenService(const std::string & tokenService) {
        this->tokenService = tokenService;
    }

private:
    std::string host;
    std::string port;
    std::string tokenService;

};

}
}

HDFS_HASH_DEFINE(::Hdfs::Internal::RpcServerInfo);
